package com.fx.educms.controller;


import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.fx.commonuntils.ReturnMessage;
import com.fx.commonuntils.ReturnMessageUtils;
import com.fx.educms.entity.CrmBanner;
import com.fx.educms.service.CrmAdminService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import lombok.RequiredArgsConstructor;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

/**
 * <p>
 * 首页banner表 前端控制器
 * </p>
 *
 * @author testjava
 * @since 2020-11-12
 */
@Api(description = "前端轮播图系统管理")
@RestController
@RequestMapping("/educms/banneradmin")
@RequiredArgsConstructor(onConstructor = @__(@Autowired))
@Slf4j
@CrossOrigin//解决跨域问题
public class CrmAdminController {
    final private CrmAdminService crmAdminService;

    //1 分页查询banner

    @ApiOperation(value = "分页查询banner")
    @GetMapping("pageBanner/{page}/{limit}")
    public ReturnMessage<Page<CrmBanner>> pageBanner(@PathVariable long page, @PathVariable long limit) {
        Page<CrmBanner> pageBanner = new Page<>(page, limit);
       crmAdminService.page(pageBanner, null);
        return ReturnMessageUtils.success(pageBanner);
        

    }



    //2 添加banner
    @ApiOperation(value = "添加banner")
    @PostMapping("addBanner")
    public ReturnMessage<Object> addBanner(@RequestBody CrmBanner crmBanner) {
        crmAdminService.save(crmBanner);
        return ReturnMessageUtils.success();
    }



    @ApiOperation(value = "获取Banner")
    @GetMapping("get/{id}")
    public ReturnMessage<Object> get(@PathVariable String id) {
        CrmBanner banner = crmAdminService.getById(id);
        return ReturnMessageUtils.success(banner);
    }

    @ApiOperation(value = "修改Banner")
    @PutMapping("update")
    public ReturnMessage<Object> updateById(@RequestBody CrmBanner banner) {
        boolean b = crmAdminService.updateById(banner);
        return ReturnMessageUtils.success();
    }

    @ApiOperation(value = "删除Banner")
    @DeleteMapping("remove/{id}")
    public ReturnMessage<Object> remove(@PathVariable String id) {
        crmAdminService.removeById(id);
        return ReturnMessageUtils.success();
    }










}

